<?php
/** 
 * stm api接口类
 * @author puppet 郭钊林
 */
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Log;
abstract class ApiBaseController extends Controller{
  protected $code = 0;
  protected $msg = '';
  protected $data;
  protected $params;

  protected function __construct(Request $request) {
    if(!$request->session()->has('user')){
		if($request->isMethod('post')){
			$this->returnJson(1,'请先登录');
		}
		return redirect('admin/login');
    }
    $this->params = $request->all();
    Log::info("in.params=".json_encode($this->params,JSON_UNESCAPED_UNICODE)." ,". __FILE__." ,".__FUNCTION__." ,".__LINE__);
  }

  protected function boot(){
    Log::info("out.code=".$this->code.", msg=".$this->msg.", data=".json_encode($this->data)." ,".__FILE__." ,".__FUNCTION__." ,".__LINE__);
    echo json_encode(['code'=>$this->code,'msg'=>$this->msg,'data'=>$this->data]);
  }
	
	//返回json 提示数据
	protected function returnJson($code,$msg,$url="",$data=array()){
		exit(json_encode(array('code'=>$code,'msg'=>$msg,'data'=>$data,'url'=>$url)));
	}
}

